import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 石仲夏
 * Date: 2025-07-05
 * Time: 18:54
 */
public class Text {
    public static void main(String[] args) {
        int[] array=new int[]{1,44,78,31,66};
        System.out.println("排序前："+Arrays.toString(array));
        Arrays.sort(array);
        System.out.println("排序后："+Arrays.toString(array));
        System.out.println(Arrays.binarySearch(array,66));
    }
    //找下标
    //二分查找---必须是有序的
    public static int binarry(int[] array,int key){
        int left=0;
        int right=array.length-1;
       while (left<=right){
           int mid=(left+right)/2;
           if(array[mid]==key){
               return mid;
           } else if (array[mid]>key) {
               right=mid-1;
           }else {
               left=mid+1;
           }
       }
       return -1;
    }
    //逐个匹配法
    public static int findnum(int[] array,int key){
        for (int i = 0; i < array.length; i++) {
            if (array[i]==key){
                return i;
            }
        }
        return -1;
    }
    public static void main5(String[] args) {
        int[] array=new int[]{1,2,3,4,5};
        int a=10;
    }
    public static void main4(String[] args) {
        int[] array=new int[]{1,2,3,4,5,6};
        String ret= Arrays.toString(array);
        System.out.println(ret);
    }
    public static void main3(String[] args) {
        int[] array=new int[]{1,2,3,4,5,6};
        for (int x: array) {
            System.out.print(x+" ");
        }
    }
    public static void main2(String[] args) {
        int[] array=new int[]{1,2,3,4,5,6};
       // System.out.println(array.length);
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i]+" ");
        }
    }
    public static void main1(String[] args) {
        int[] array=new int[]{1,2,3,4,5,6};//定义和初始化
        int[] array2={1,2,3,4,5,6};       //简单版，编译时会还原
        int[] array3=new int[6];          //未初始化，默认值都为零
    }
}
